<style lang="less">
  @import '../styles/common.less';
  @import '../tables/components/table.less';
</style>

<template>
  <div class="div-relative">
    <Card>
      <p slot="title">
        <Icon type="person"></Icon>
        离退休设置
      </p>
      <div style="min-height: 380px;">
        <Form
            ref="userForm"
            :model="InfoObj"
            :label-width="200"
            label-position="right"
        >
          <FormItem label="男退休年龄：">
            <div style="display:inline-block;width:300px;">
              <InputNumber :max="100" :min="1" v-model="InfoObj.male_age" class="InputNumber"></InputNumber>
            </div>
          </FormItem>
          <FormItem label="女退休年龄：">
            <div style="display:inline-block;width:300px;">
              <InputNumber :max="100" :min="1" v-model="InfoObj.female_age" class="InputNumber"></InputNumber>
            </div>
          </FormItem>
          <FormItem label="默认离退休提醒时间：">
            <div style="display:inline-block;width:300px;">
              <Select v-model="InfoObj.remind" :transfer="true" style="width:100%;">
                <Option v-for="item in remindArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
              </Select>
            </div>
          </FormItem>
          <FormItem label="离退休查询时间：">
            <div style="display:inline-block;width:300px;">
              <Select v-model="InfoObj.listTime" :transfer="true" style="width:100%;">
                <Option v-for="item in listTimeArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
              </Select>
            </div>
          </FormItem>
          <div style="padding-left: 200px;">
            <!--<Button type="text" style="width: 100px;" @click="cancelEditUserInfor">取消</Button>-->
            <Button type="primary" style="width: 100px;" :loading="save_loading" @click="saveInfoAjax">保存</Button>
          </div>
        </Form>
      </div>
    </Card>
  </div>
</template>

<script>
  import Cookies from 'js-cookie';
  import Util from '../../libs/util';
  import Utils from '../../libs/mod.utils';
  import Nim from '../../libs/mod.nim';
  import String from '../../libs/mod.string';
  import Modal from '../../libs/mod.Modal';
  export default {
    name: 'user_retirelSetup',
    data () {
      return {
        InfoObj: {
          male_age: 60,
          female_age: 60,
          remind: 'no',
          listTime: '1',
          id: '',
        },
        uid: '', // 登录用户的userId
        save_loading: false,
        remindArr: [
          {
            id: 'no',
            name: '不提醒'
          },
          {
            id: 'month',
            name: '一个月'
          },
          {
            id: 'year',
            name: '一年'
          }
        ],
        listTimeArr: [
          {
            id: '1',
            name: '一年'
          },
          {
            id: '2',
            name: '两年'
          },
          {
            id: '3',
            name: '三年'
          },
          {
            id: '5',
            name: '五年'
          }
        ],
      };
    },
    mounted () {
      var _this = this;
      _this.getSetup();
    },
    methods: {
      getSetup () {
        var _this = this;
        var data = {};
        var params = {
          url: '/retired/query',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data;
            var id = data.id;
            var list_time = data.list_time;
            var remind = data.remind;
            var female_age = data.female_age;
            var male_age = data.male_age;
            _this.InfoObj.listTime = list_time.toString();
            _this.InfoObj.id = id;
            _this.InfoObj.remind = remind;
            _this.InfoObj.female_age = female_age;
            _this.InfoObj.male_age = male_age;
          } else {
            _this.$Message.destroy();_this.$Message.error('查询信息失败!');
          }
        }
      },
      // 保存
      saveInfoAjax () {
        var _this = this;
        if (!_this.InfoObj.male_age) {
          _this.$Message.destroy();_this.$Message.error('请填写男退休年龄!');
          return false;
        }
        if (!_this.InfoObj.female_age) {
          _this.$Message.destroy();_this.$Message.error('请填写女退休年龄!');
          return false;
        }
        var data = {
          id: _this.InfoObj.id,
          male_age: _this.InfoObj.male_age,
          female_age: _this.InfoObj.female_age,
          remind: _this.InfoObj.remind,
          listTime: _this.InfoObj.listTime,
        };
        var params = {
          url: '/retired/setup',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.save_loading = true;
        function _successFun(res) {
          _this.save_loading = false;
          if (res.result == 0) {
            var _data = res.data || {};
            _this.$Message.destroy();_this.$Message.success('保存成功!');
          } else {
            _this.$Message.destroy();_this.$Message.error('保存失败!');
          }
        }
      },
      // 取消
      cancelEditUserInfor: function () {
        var _this = this;
        _this.$store.commit('removeTag', 'user_retirelSetup');
        localStorage.pageOpenedList = JSON.stringify(_this.$store.state.app.pageOpenedList);
        let lastPageName = '';
        if (_this.$store.state.app.pageOpenedList.length > 1) {
          lastPageName = _this.$store.state.app.pageOpenedList[1].name;
        } else {
          lastPageName = _this.$store.state.app.pageOpenedList[0].name;
        }
        _this.$router.push({
          name: lastPageName
        });
      },

    }
  };
</script>

